#pragma once
#include "protocols/protocal.h"
#include "Protocols/PacketHeader.h"
#include "utilities/utilities.h"


class IcmpHeader : public PacketHeader {
public:
	IcmpHeader(ProtocolPtr id,const unsigned char* data,size_t pos,size_t length):PacketHeader(id,data,pos,length) {
		mLength = getHeaderLength();
	}

	struct HeaderFormat {
		u_char  mType;            // Type
		u_char mCode;           // Code
		u_char mCRC[2];            // Header checksum
		unsigned char mIdentifier[2];      // Identifier
		u_short mSequenceNumber;		// SequenceNumber
		unsigned char mData;         // Data
	};

	HeaderFormat* get() const {
		return (HeaderFormat*)mData;
	}
	
	int getHeaderType() const{
		return ((HeaderFormat *)mData)->mType;
	}
	int getHeaderCode() const{
		return ((HeaderFormat *)mData)->mCode;
	}
	void toShowableItems(ShowableItem* root) const;
	
	QString getSummary() const;
	
	int getHeaderLength() const{
		return 8;
	}
};


DECLARE_PROTOCOL_BEGIN(Icmp,IcmpHeader)
DECLARE_PROTOCOL_END